package com.luoyuanxiangvip.common.utils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author: luoyuanxiang
 * @className: AjaxResult
 * @packageName: com.luoyuanxiangvip.common.utils
 * @description: 返回json
 * @data: 2019/5/25 20:53
 **/
@Data
public class AjaxResult {

    @ApiModelProperty(value = "code")
    private Integer code;

    @ApiModelProperty(value = "消息描述")
    private String message;

    @ApiModelProperty(value = "返回参数")
    private Object result;

    private AjaxResult() {
        this.code = 0;
        this.message = "操作成功";
        this.result = null;
    }

    private AjaxResult(Integer code,String msg) {
        this.code = code;
        this.message = msg;
        this.result = null;
    }

    private AjaxResult(Integer code,String msg,Object data) {
        this.code = code;
        this.message = msg;
        this.result = data;
    }

    private AjaxResult(Object data) {
        this.code = 0;
        this.message = "操作成功";
        this.result = data;
    }

    private AjaxResult(String msg) {
        this.code = 0;
        this.message = msg;
        this.result = null;
    }

    public static AjaxResult success() {
        return new AjaxResult();
    }

    public static AjaxResult success(String msg) {
        return new AjaxResult(msg);
    }

    public static AjaxResult success(Integer code,String msg) {
        return new AjaxResult(code,msg);
    }

    public static AjaxResult success(Object data) {
        return new AjaxResult(data);
    }

    public static AjaxResult success(String message,Object data) {
        return new AjaxResult(0, message, data);
    }

    public static AjaxResult success(Integer code,String msg,Object data) {
        return new AjaxResult(code,msg,data);
    }


    public static AjaxResult error() {
        return new AjaxResult(500,"操作失败");
    }

    public static AjaxResult error(String msg) {
        return new AjaxResult(500,msg);
    }

    public static AjaxResult error(Integer code,String msg) {
        return new AjaxResult(code,msg);
    }
}
